﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//想让另外一个RectTransfrom随着自己的大小变化
public class SizeFit : MonoBehaviour
{
    public RectTransform other;
    private RectTransform self;
    public bool update;
    public Vector2 padding = new Vector2(5, 5);//留白

    private IEnumerator Start()
    {
        yield return null;
        self = transform as RectTransform;
        other.sizeDelta = self.sizeDelta + padding;
        if (update)
        {
            StartCoroutine("_Update");
        }
    }

    private IEnumerator _Update()
    {
        while (true)
        {
            other.sizeDelta = self.sizeDelta + padding;
            yield return null;
        }
    }
}